<template>
	<view class="contentBox">
		<u-navbar title="" height="120upx">
			<view class="u-nav-slot" slot="left"></view>
			<view class="u-nav-slot logoBox" slot="center">
				<view class="navBox">开户结果</view>
			</view>
			<view class="u-nav-slot" slot="right">
				<view class="icon-right"></view>
			</view>
		</u-navbar>
		
		<view v-if="status == 0">
			<view class="main" v-if="response.subCode == 'Z5051'">
				<view class="title">认证失败</view>
				<view class="explain">上传刷脸图片失败!</view>
			</view>
			<view class="main" v-else-if="response.subCode == 'Z5052'">
				<view class="title">认证失败</view>
				<view class="explain">数据错误或程序异常!</view>
			</view>
			<view class="main" v-else-if="response.subCode == 'Z5053'">
				<view class="title">认证失败</view>
				<view class="explain">网络错误!</view>
			</view>
			<view class="main" v-else-if="response.subCode == 'Z5054'">
				<view class="title">认证失败</view>
				<view class="explain">摄像头无权限或者无法获取摄像头数据出错!</view>
			</view>
			<view class="main" v-else-if="response.subCode == 'Z5055'">
				<view class="title">认证失败</view>
				<view class="explain">用户退出认证</view>
			</view>
			<view class="main" v-else-if="response.subCode == 'Z5056'">
				<view class="title">认证失败</view>
				<view class="explain">重试次数过多!</view>
			</view>
		</view>
		
		<view v-else-if="status == 1">
			<view class="main">
				<view class="title">资料提交成功</view>
				<view class="explain">确认开通后即可成功开户！</view>
			</view>
		</view>
		
		<view v-else>
			<view class="main">
				<view class="title">开通失败</view>
				<view class="explain">{{errMsg}}!</view>
			</view>
		</view>
		
		 <view class="btn" v-if="status != 1 && status != 3">
		 	<text @tap="recertification">重新认证</text>
		 </view>
		 
		<view class="btn" v-else>
			<text @tap="navTo">确认开通</text>
		</view>
		
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {dsbankuserAdd,} from '../../api/user.js'
	export default {
		data(){
			return {
				status:0,
				response:{},
				errMsg:""
			}
		},
		onLoad(opt) {
			if(opt.response){
				let response = decodeURIComponent(decodeURIComponent(opt.response));
				response = JSON.parse(response);
				this.response = response;
				if(response.subCode != "Z5051" && response.subCode != "Z5052" && response.subCode != "Z5053" && response.subCode != "Z5054" && response.subCode != "Z5055" && response.subCode != "Z5056"){
					this.status = 1;
				}
			}
		},
		methods:{
			recertification(){
				uni.redirectTo({
					url:"/pages/openAccount/openAccountAgreement"
				});
				try {
					uni.removeStorageSync('openAccountObj');
				} catch (e) {
					// error
				}
			},
			navTo(cur){
				let obj = {};
				try {
					obj = uni.getStorageSync('openAccountObj');
				} catch (e) {
					// error
				}
				
				dsbankuserAdd(obj).then(res => {
					if (res.data.success) {
						this.$refs.uToast.show({
							type: 'success',
							message: "开通成功！",
							iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
						});
						this.$store.dispatch("getuser",2);
						try {
							uni.removeStorageSync('openAccountObj');
						} catch (e) {
							// error
						}
						setTimeout(()=>{
							uni.redirectTo({
								url:"/pages/user/myAssets"
							});
						},1000);
					} else {
						this.status = 3;
						this.errMsg = res.data.msg;
						this.$u.toast(res.data.msg);
					}
				}).catch(err => {
					this.status = 3;
					this.errMsg = "网络错误，稍后重试！";
					this.$u.toast('网络错误，稍后重试！');
				});
			},
		},
		onUnload(){
			try {
				uni.removeStorageSync('openAccountObj');
			} catch (e) {
				// error
			}
		}
	}
</script>

<style lang="scss" scoped>
	.contentBox{
		padding-top: 120upx;
		background-color: #fff;
		min-height: 100vh;
		.btn{
			position: fixed;
			bottom: 0upx;
			left: 0;
			width: 100%;
			text-align: center;
			padding:100upx 58upx;
			background-color: #fff;
			text{
				display: block;
				height: 100%;
				color: #fff;
				width: 100%;
				background-color: #2c1769;
				font-size: 30upx;
				line-height: 100upx;
			}
		}
		.main{
			.title{
				padding-top: 160upx;
				padding-bottom:60upx;
				text-align: center;
				font-size: 36upx;
				color: #333;
				font-weight: bold;
			}
			.explain{
				text-align: center;
				font-size: 24upx;
				color: #999;
				padding: 0 58upx;
				text-align: center;
			}
		}
		.logoBox{
			width: 100%;
			height: 100%;
			.navBox{
				height: 120upx;
				background-image: url("@/static/common/bg1.png");
				background-size: 100% 100%;
				background-repeat: no-repeat;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #fff;
			}
		}
	}
</style>
